package com.xinjie.www.service.tieba;

import com.xinjie.www.dao.BaseDao;
import com.xinjie.www.dao.tieba.TiebaDao;
import com.xinjie.www.dao.tieba.TiebaDaoImpl;
import com.xinjie.www.po.Tieba;

import java.sql.Connection;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

public class TiebaServiceImpl implements TiebaService{
    private final TiebaDao tiebaDao;
    public TiebaServiceImpl(){
        tiebaDao = new TiebaDaoImpl();
    }

    @Override
    public List<Tieba> getAllTieba() throws SQLException, ClassNotFoundException {
        List<Tieba> tiebas = new ArrayList<>();
        Connection conn = null;
        conn = BaseDao.getConnection();
        tiebas = tiebaDao.getAllTieba(conn);
        BaseDao.closeResource(conn,null,null);
        return tiebas;
    }

    @Override
    public List<Tieba> getOwnTieba(String manager) throws SQLException, ClassNotFoundException {
        List<Tieba> tiebas = new ArrayList<>();
        Connection conn = null;
        conn = BaseDao.getConnection();
        tiebas = tiebaDao.getOwnTieba(conn,manager);
        BaseDao.closeResource(conn,null,null);
        return tiebas;
    }
}
